// 
//  Indicator.js
//  Sinatay_TouBao
//  
//  Created by 梁宏远 on 2012-11-14.
//  Copyright 2012 梁宏远 All rights reserved.
// 

exports.create = function(options){
	options = options || {};
	options.msg = options.msg || '加载中,请稍后...';
	// window container
	var indWin = Titanium.UI.createWindow({
		height : '100%',
		width : '100%',
		backgroundImage:options.backgroundImage,
	});
	
	var bkView = Ti.UI.createView({
		height:'100%',
		height:'100%',
		backgroundColor:options.backgroundColor || 'transparent',
		opacity:options.opacity || 0.6
	});
	indWin.add(bkView);
	
	// black view
	var indView = Titanium.UI.createView({
		height : 150,
		width : 150,
		backgroundColor : options.inbkcolor || 'transparent',
		borderRadius : 10,
		opacity : options.inopacity || 0.8
	});

	indWin.add(indView);
	// loading indicator
	var actInd = Titanium.UI.createActivityIndicator({
		style : Titanium.UI.iPhone.ActivityIndicatorStyle.BIG,
		height : 30,
		width : 30
	});
	indWin.add(actInd);
	// message
	var message = Titanium.UI.createLabel({
		text : options.msg,
		color : '#fff',
		width : 'auto',
		height : 'auto',
		textAlign : 'center',
		font : {
			fontFamily : 'Helvetica Neue',
			fontSize : 12,
			fontWeight : 'bold'
		},
		bottom : 20
	});

	indView.add(message);
	
	//加载进度窗体
	this.show = function(msg) {
		message.text = msg || options.msg;
		indWin.open();
		actInd.show();
	};
	//更新显示的内容
	this.updateMsg = function(msg){
	    message.text = msg;
	}
	
	//隐藏进度窗体
	this.hide = function() {
		actInd.hide();
		indWin.close();
	};
	
	return this;
}
